package com.sqlcheck.dto.response;

import com.sqlcheck.enums.TaskStage;
import lombok.Builder;
import lombok.Data;

import java.util.List;
import java.util.Map;

/**
 * 任务进度信息
 */
@Data
@Builder
public class TaskProgressInfo {
    
    /**
     * 任务ID
     */
    private Long taskId;
    
    /**
     * 当前进度百分比 (0-100)
     */
    private Integer progress;
    
    /**
     * 当前阶段
     */
    private TaskStage currentStage;
    
    /**
     * 进度消息
     */
    private String message;
    
    /**
     * 是否为里程碑节点
     */
    private Boolean isMilestone;
    
    /**
     * 里程碑标题
     */
    private String milestoneTitle;
    
    /**
     * 里程碑描述
     */
    private String milestoneDescription;
    
    /**
     * 详细统计信息
     */
    private Map<String, Object> statistics;
    
    /**
     * 预估剩余时间（秒）
     */
    private Long estimatedRemainingSeconds;
    
    /**
     * 已完成的里程碑列表
     */
    private List<MilestoneInfo> completedMilestones;
    
    /**
     * 时间戳
     */
    private Long timestamp;
    
    /**
     * 里程碑信息
     */
    @Data
    @Builder
    public static class MilestoneInfo {
        private TaskStage stage;
        private String title;
        private String description;
        private Long completedAt;
        private Integer progress;
        private Map<String, Object> metrics;
    }
    
    /**
     * 创建里程碑进度信息
     */
    public static TaskProgressInfo milestone(Long taskId, TaskStage stage, String title, 
                                           String description, Map<String, Object> statistics) {
        return TaskProgressInfo.builder()
                .taskId(taskId)
                .progress(stage.getEndProgress())
                .currentStage(stage)
                .message(title)
                .isMilestone(true)
                .milestoneTitle(title)
                .milestoneDescription(description)
                .statistics(statistics)
                .timestamp(System.currentTimeMillis())
                .build();
    }
    
    /**
     * 创建普通进度信息
     */
    public static TaskProgressInfo progress(Long taskId, TaskStage stage, int progress, String message) {
        return TaskProgressInfo.builder()
                .taskId(taskId)
                .progress(progress)
                .currentStage(stage)
                .message(message)
                .isMilestone(false)
                .timestamp(System.currentTimeMillis())
                .build();
    }
}